<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表格操作</title>
</head>
<body>
<table id="tab" border="1">
    <tr>
        <th>姓名</th>
        <th>年龄</th>
    </tr>
    <tr>
        <td>张三</td>
        <td>18</td>
    </tr>
</table>

</body>
<script>
    let tab = document.getElementById("tab");
    //获取表格的所有行
    let rows = tab.rows;
    console.log(rows);
    //获取表格中行的数量
    let tablength = rows.length;
    console.log(tablength);
    //向表格中插入新的一行
    let row1 = tab.insertRow(2);
    //向行中插入单元格
    let cell0 = row1.insertCell(0);
    cell0.innerHTML="王五";
    let cell1 = row1.insertCell(1);
    cell1.innerHTML="22";
    //获取指定行
    let row2 = tab.rows[2];
    console.log(row2);
    //获取指定行的所有单元格
    let cells1 = row2.cells;
    console.log(cells1);
    //获取指定行的指定单元格
    let cells2s = row2.cells[1];
    let cells2 = cells1[1];
    console.log(cells2);
    console.log(cells2s);
    //删除指定单元格
    row2.deleteCell(1);
    //删除指定行
    tab.deleteRow(2);
</script>
</html>